package com.learn.springboot3.config;

import com.learn.springboot3.job.MailsJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ClassName: QuartzConfig
 * Package: com.learn.springboot3.config
 * Description:
 *
 * @Author jiangCheng
 * @Create 2024/10/21 14:34
 * @Version 1.0
 */
@Configuration
public class QuartzConfig {
    @Bean
    public JobDetail myJobDetail() {
        return JobBuilder.newJob(MailsJob.class)
                .withIdentity("MailsJob")
                .storeDurably()
                .build();
    }
    @Bean
    public Trigger myCronTrigger() {
        return TriggerBuilder.newTrigger()
                .forJob(myJobDetail())
                .withIdentity("myCronTrigger")
                // 每10秒执行
                .withSchedule(CronScheduleBuilder.cronSchedule("0/10 0/10 * * * ?"))
                .build();
    }


//    @Bean
//    public Trigger myTrigger() {
//        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
//                .withIntervalInSeconds(10)
//                .repeatForever();
//
//        return TriggerBuilder.newTrigger()
//                .forJob(myJobDetail())
//                .withIdentity("myTrigger")
//                .withSchedule(scheduleBuilder)
//                .build();
//    }
}
